package com.one.consumer.common.state;

import android.view.View;
import android.widget.TextView;

import com.one.common.config.OrderState;
import com.one.consumer.R;
import com.one.consumer.main.model.item.OrderItem;

/**
 * Author: zhulunjun
 * Time  : 2018/11/2 11:12
 * email : zhulunjun@qq.com
 * Describe : 订单状态相关处理
 **/
public class OrderStateHandle {

    /**
     * 各状态下按钮的显示
     * 列表页面
     */
    public static void setStateView(OrderItem item, TextView btn1, TextView btn2, TextView btn3) {

        String state = item.getOrder_state();
        switch (state) {
            case OrderState.WAIT_ASSIGNED: // 待指派
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.GONE);
                btn3.setVisibility(View.GONE);
                btn3.setText("查看详情");
                break;
            case OrderState.WAIT_VISIT: // 待上门
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.GONE);
                btn3.setVisibility(View.VISIBLE);
                btn3.setText("查看详情");
                break;
            case OrderState.WAIT_CONFIRM: // 等待确认服务
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.GONE);
                btn3.setVisibility(View.VISIBLE);
                btn3.setText("立即确认");
                break;
            case OrderState.WAIT_PAY: // 待付款
                btn1.setVisibility(View.GONE);
                btn2.setVisibility(View.GONE);
                btn3.setVisibility(View.VISIBLE);
                btn3.setText("立即支付");
                break;
            case OrderState.PAY_END: // 已付款
                btn1.setVisibility(View.GONE);
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.VISIBLE);
                btn3.setText("立即评价");
                if (item.getAssessment_state().equals("2")) {
                    btn3.setVisibility(View.GONE);
                }
                break;
            case OrderState.CANCEL:
                btn1.setVisibility(View.GONE);
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.GONE);
                break;
            default:
                btn1.setVisibility(View.GONE);
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.GONE);
                break;
        }
    }

    public static String getStateStr(OrderItem item) {
        String state = item.getOrder_state();
        String result;
        switch (state) {
            case OrderState.WAIT_ASSIGNED:
                result = "等待指派师傅接单";
                break;
            case OrderState.WAIT_VISIT:
                result = "等待指派师傅上门 ";
                break;
            case OrderState.WAIT_CONFIRM:
                result = "确认订单";
                break;
            case OrderState.WAIT_PAY:
                result = "待支付";
                break;
            case OrderState.PAY_END:
                if (item.getAssessment_state().equals("2")) {
                    result = "已评价";
                } else {
                    result = "待评价";

                }
                break;
            case OrderState.CANCEL:
                result = "已关闭";
                break;
            default:
                result = "等待指派师傅接单";
                break;
        }
        return result;
    }


    /**
     * 各状态下按钮的显示
     * 详情页面
     */
    public static void setStateViewDetail(OrderItem item, TextView btn1,
                                          TextView btn2, TextView btn3,
                                          TextView btn4, TextView btn5) {

        String state = item.getOrder_state();
        switch (state) {
            case OrderState.WAIT_ASSIGNED: // 待指派
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.GONE);
                btn3.setVisibility(View.VISIBLE);
                btn4.setVisibility(View.GONE);
                btn5.setVisibility(View.GONE);
                break;
            case OrderState.WAIT_VISIT: // 待上门
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.GONE);
                btn3.setVisibility(View.VISIBLE);
                btn4.setVisibility(View.VISIBLE);
                btn5.setVisibility(View.GONE);
                btn4.setText("联系师傅");
                break;
            case OrderState.WAIT_CONFIRM: // 等待确认服务
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.GONE);
                btn3.setVisibility(View.VISIBLE);
                btn4.setVisibility(View.VISIBLE);
                btn5.setVisibility(View.GONE);
                btn4.setText("立即确认 ");
                break;
            case OrderState.WAIT_PAY: // 待付款
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.GONE);
                btn3.setVisibility(View.VISIBLE);
                btn4.setVisibility(View.VISIBLE);
                btn5.setVisibility(View.GONE);
                btn4.setText("立即支付");
                break;
            case OrderState.PAY_END: // 已付款
                btn1.setVisibility(View.GONE);
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.VISIBLE);
                btn4.setVisibility(View.VISIBLE);
                btn5.setVisibility(View.VISIBLE);
                btn4.setText("索要发票");
                if (!item.getAssessment_state().equals("1")) {
                    btn5.setText("已评价");
                    btn5.setEnabled(false);
                    btn5.setBackgroundResource(R.drawable.shape_bg_gray_b5_r2);
                }
                if (!item.getInvoice_state().equals("1")) {
                    btn4.setEnabled(false);
                    btn4.setBackgroundResource(R.drawable.shape_bg_gray_b5_r2);
                    btn4.setText("已索取发票");
                }
                break;
            case OrderState.CANCEL:
                btn1.setVisibility(View.GONE);
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.GONE);
                btn4.setVisibility(View.GONE);
                btn5.setVisibility(View.GONE);
                break;
            default:
                btn1.setVisibility(View.GONE);
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.GONE);
                btn4.setVisibility(View.GONE);
                btn5.setVisibility(View.GONE);
                break;
        }
    }
}
